home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 27.zip / BS1 part 27 / ImageMaster_d3.adf / dd.LZH / negative.c < prev    next >
C/C++ Source or Header  |  1990-03-30  |  3KB  |  114 lines

  1. /*
  2.  * negative.c - Does a simple negative in Imagemaster
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. struct jackinbuff
  8.   {
  9.     unsigned char *red;
  10.     unsigned char *green;
  11.     unsigned char *blue;
  12.     unsigned char *mask;
  13.     unsigned short x;
  14.     unsigned short y;
  15.   };
  16.  
  17. struct jackina
  18.   {
  19.     struct jackinbuff *primary;
  20.     struct jackinbuff *secondary;
  21.     struct jackinbuff *undo;
  22.     struct jackinbuff *blend;
  23.     struct jackinbuff *brush;
  24.     unsigned char     *mask;
  25.     char              jack[4];
  26.   };
  27.  
  28. static struct jackina *jackins;
  29. static struct jackinbuff *primary_jack;
  30. static struct jackinbuff *secondary_jack;
  31. static struct jackinbuff *undo_jack;
  32. static struct jackinbuff *blend_jack;
  33. static struct jackinbuff *brush_jack;
  34.  
  35. main(argc,argv)
  36. int    argc;
  37. char   *argv[];
  38.   {
  39.   unsigned int tpoint,x,y,xw,yw,offset,yoffset;
  40.   unsigned char rr,gg,bb;
  41.   
  42.   unsigned char *rbu;
  43.   unsigned char *gbu;
  44.   unsigned char *bbu;
  45.   
  46.     printf("NEGATIVE <pointer to IM jackin structure>\n");
  47.     printf("A simple Imagemaster Public Interface operation.\n");
  48.   
  49.     if (argc <= 1)
  50.       {
  51.         printf("NEGATIVE : No argument supplied!\n");
  52.         return(1);
  53.       }
  54.     else
  55.       {
  56.         sscanf(argv[1],"%X",&tpoint);
  57.       }
  58.     if (tpoint == 0)
  59.       {
  60.         printf("NEGATIVE : Argument is ZERO!\n");
  61.         return(1);
  62.       }
  63.       
  64.     jackins = (struct jackina *)tpoint;
  65.       
  66.     if (jackins->jack[0] != 'J' ||
  67.         jackins->jack[1] != 'A' ||
  68.         jackins->jack[2] != 'C' ||
  69.         jackins->jack[3] != 'K' )
  70.       {
  71.         printf("NEGATIVE : Problem in information passed from Imagemaster!\n");
  72.         return(1);
  73.       }
  74.     if (jackins->primary == NULL)
  75.       {
  76.         printf("NEGATIVE : Primary buffer is NULL!\n");
  77.         return(1);
  78.       }
  79.     xw = jackins->primary->x;
  80.     yw = jackins->primary->y;
  81.     if (xw == 0 || yw == 0)
  82.       {
  83.         printf("NEGATIVE : Primary buffer is Empty!\n");
  84.         return(1);
  85.       }
  86.     rbu = jackins->primary->red;
  87.     gbu = jackins->primary->green;
  88.     bbu = jackins->primary->blue;
  89.     if (rbu == NULL || gbu == NULL || bbu == NULL)
  90.       {
  91.         printf("NEGATIVE : Primary buffer is corrupted!\n");
  92.         return(1);
  93.       }
  94.     /* Run through the image */
  95.     for (y=0; y<yw; y++)
  96.       {
  97.         printf(".");
  98.         yoffset = y * xw;
  99.         for (x=0; x<=xw; x++)
  100.           {
  101.             offset = yoffset + x;
  102.             rr = *(rbu+offset);
  103.             gg = *(gbu+offset);
  104.             bb = *(bbu+offset);
  105.             *(rbu+offset) = 255 - rr;  /* This is a color negative */
  106.             *(gbu+offset) = 255 - gg;
  107.             *(bbu+offset) = 255 - bb;
  108.           }
  109.       }
  110.     printf("\n");
  111.     return(0);
  112.   }
  113.  
  114.